import datetime
import time
import functools


# 只判断时间的装饰器logger(fun)
def logger(fn):
    @functools.wraps(fn)
    def inner(*args, **kwargs):
        starttime = datetime.datetime.now()
        print('Fn start at {} '.format(starttime))
        ret = fn(*args, **kwargs)
        delta = (datetime.datetime.now() - starttime).total_seconds()
        print('程序共运行{}秒'.format(delta))
        return ret

    return inner


# 接受传参的装饰器logger1(t:int)
def logger1(t: int):
    def wrapper(fun):
        def wrapper1(*args, **kwargs):
            start = datetime.datetime.now()
            ret = fun(*args, **kwargs)
            delta = (datetime.datetime.now() - start).total_seconds()
            if delta > t:
                print('大于{}秒的程序是：{},其运行时间是：{}'.format(t, fun.__name__, delta))
            return ret

        return wrapper1

    return wrapper


@logger1(3)
@logger
def fun(t=2):
    print('Fun:sleep {} second'.format(t))
    time.sleep(t)


def main():
    fun(3)


if __name__ == '__main__':
    main()
# 逻辑上没有问题